<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * @property Threads $threads
 * @property WebSocket $websocket
 */
class Welcome extends CI_Controller
{

	public function __construct()
	{
		parent::__construct();
	}

	public function index()
	{
		$config = $this->config->item('websocket_server');
		$this->load->library('WebSocket');
		$this->websocket->loadSetting(APPPATH . "/config/swoole.ini"); //加载配置文件
		$this->websocket->setLogger(new \Swoole\Log\EchoLog(true)); //Logger

		/**
		 * 如果你没有安装swoole扩展，这里还可选择
		 * BlockTCP 阻塞的TCP，支持windows平台
		 * SelectTCP 使用select做事件循环，支持windows平台
		 * EventTCP 使用libevent，需要安装libevent扩展
		 */
		$enable_ssl = false;
		$server = Swoole\Network\Server::autoCreate($config['host'], $config['port'], $enable_ssl);
		$server->setProtocol($this->websocket);
		if($config['daemonize'] === TRUE) $server->daemonize(); //作为守护进程
		$server->run($config['setting']);
	}

}